//
//  MyLonsCell.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/6.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "MyLonsCell.h"
#import "MyLonsFunctionView.h"

@interface MyLonsCell ()

@property (nonatomic, strong) UILabel *orderCodeLabel;
@property (nonatomic, strong) UILabel *orderStateLabel;
@property (nonatomic, strong) MyLonsFunctionView *leftFunctionView;
@property (nonatomic, strong) MyLonsFunctionView *midFunctionView;
@property (nonatomic, strong) MyLonsFunctionView *rightFunctionView;
@property (nonatomic, strong) UILabel *orderTimeLabel;

@end

@implementation MyLonsCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = ListMaoBackgroundColor;
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_equalTo(self.contentView);
            make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-45);
        }];
        
        UIView *whiteView = [[UIView alloc] init];
        whiteView.userInteractionEnabled = NO;
        whiteView.layer.cornerRadius = 4;
        whiteView.layer.masksToBounds = YES;
        whiteView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:whiteView];
        [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView.mas_left).offset(12);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-12);
            make.top.mas_equalTo(self.contentView.mas_top).offset(12);
            make.bottom.mas_equalTo(self.contentView);
        }];
        
        UITapGestureRecognizer *longPre = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction)];
        [self.orderCodeLabel addGestureRecognizer:longPre];
        self.orderCodeLabel.userInteractionEnabled = YES;
        [self.orderCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(whiteView.mas_top).offset(4);
            make.left.mas_equalTo(whiteView.mas_left).offset(15);
            make.height.mas_equalTo(41);
            make.right.mas_equalTo(self.orderStateLabel.mas_left).offset(-8);
        }];
        [self.orderStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(whiteView.mas_top).offset(4);
            make.right.mas_equalTo(whiteView.mas_right).offset(-15);
            make.height.mas_equalTo(41);
            make.width.mas_greaterThanOrEqualTo(40);
        }];
        
        UIImageView *topLine = [[UIImageView alloc] init];
        topLine.backgroundColor = ThemeMaoLineColor;
        [whiteView addSubview:topLine];
        [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(whiteView.mas_left).offset(15);
            make.right.mas_equalTo(whiteView.mas_right).offset(-15);
            make.bottom.mas_equalTo(self.orderStateLabel.mas_bottom);
            make.height.mas_equalTo(0.5f);
        }];
        
        
        
        
        [self.orderTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(45);
            make.left.mas_equalTo(whiteView.mas_left).offset(15);
            make.bottom.mas_equalTo(whiteView.mas_bottom);
            make.right.mas_equalTo(whiteView.mas_right).offset(-90);
        }];
        
        UIImageView *bottomLine = [[UIImageView alloc] init];
        bottomLine.backgroundColor = ThemeMaoLineColor;
        [whiteView addSubview:bottomLine];
        [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(whiteView.mas_left).offset(15);
            make.right.mas_equalTo(whiteView.mas_right).offset(-15);
            make.bottom.mas_equalTo(self.orderTimeLabel.mas_top);
            make.height.mas_equalTo(0.5f);
        }];
        
        [self.leftFunctionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(whiteView.mas_left);
            make.top.mas_equalTo(topLine.mas_bottom);
            make.bottom.mas_equalTo(bottomLine.mas_top);
        }];
        [self.midFunctionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(topLine.mas_bottom);
            make.bottom.mas_equalTo(bottomLine.mas_top);
            make.left.mas_equalTo(self.leftFunctionView.mas_right);
            make.width.mas_equalTo(self.leftFunctionView.mas_width);
        }];
        [self.rightFunctionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(topLine.mas_bottom);
            make.bottom.mas_equalTo(bottomLine.mas_top);
            make.right.mas_equalTo(whiteView.mas_right);
            make.left.mas_equalTo(self.midFunctionView.mas_right);
            make.width.mas_equalTo(self.midFunctionView.mas_width);
        }];
        
        UIButton *infoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        infoBtn.userInteractionEnabled = NO;
        [infoBtn setTitle:@"查看详情＞" forState:UIControlStateNormal];
        [infoBtn setTitleColor:HexColor(0x999999) forState:UIControlStateNormal];
        infoBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [whiteView addSubview:infoBtn];
        [infoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(45);
            make.bottom.mas_equalTo(whiteView.mas_bottom);
            make.right.mas_equalTo(whiteView.mas_right).offset(-15);
            make.width.mas_equalTo(70);
        }];
    }
    return self;
}


- (void)updateInfoCellWithModel {
    
    self.orderCodeLabel.text = @"订单编号：AS15335963VDV22";
    self.orderStateLabel.text = @"待还款";
    self.orderTimeLabel.text = @"签约时间: 2017-06-10 19:39:40";
    
    NSMutableAttributedString *attributedString1 = [[NSMutableAttributedString alloc] initWithString:@"5000元"];
    [attributedString1 addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:20] range:NSMakeRange(0, attributedString1.length - 1)];
    [attributedString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(attributedString1.length - 1, 1)];
    self.leftFunctionView.topLabel.attributedText = attributedString1;
    NSMutableAttributedString *attributedString2 = [[NSMutableAttributedString alloc] initWithString:@"833.33元"];
    [attributedString2 addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:20] range:NSMakeRange(0, attributedString2.length - 1)];
    [attributedString2 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(attributedString2.length - 1, 1)];
    self.midFunctionView.topLabel.attributedText = attributedString2;
    NSMutableAttributedString *attributedString3 = [[NSMutableAttributedString alloc] initWithString:@"6个月"];
    [attributedString3 addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:20] range:NSMakeRange(0, attributedString3.length - 2)];
    [attributedString3 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(attributedString3.length - 2, 2)];
    self.rightFunctionView.topLabel.attributedText = attributedString3;
}

- (void)longPressAction {
    
    [HUD_Mao showSuccessMessage:@"订单号已复制"];
    UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
    [pasteboard setString:self.orderCodeLabel.text];
}

- (MyLonsFunctionView *)leftFunctionView {
    
    if (!_leftFunctionView) {
        _leftFunctionView = [[MyLonsFunctionView alloc] init];
        _leftFunctionView.bottomLabel.text = @"借款金额";

        [self.contentView addSubview:_leftFunctionView];
    }
    return _leftFunctionView;
}
- (MyLonsFunctionView *)midFunctionView {
    
    if (!_midFunctionView) {
        _midFunctionView = [[MyLonsFunctionView alloc] init];
        _midFunctionView.bottomLabel.text = @"月供金额";

        [self.contentView addSubview:_midFunctionView];
    }
    return _midFunctionView;
}
- (MyLonsFunctionView *)rightFunctionView {
    
    if (!_rightFunctionView) {
        _rightFunctionView = [[MyLonsFunctionView alloc] init];
        _rightFunctionView.bottomLabel.text = @"分期期数";

        [self.contentView addSubview:_rightFunctionView];
    }
    return _rightFunctionView;
}

- (UILabel *)orderCodeLabel {
    
    if (!_orderCodeLabel) {
        _orderCodeLabel = [[UILabel alloc] init];
        [_orderCodeLabel setTextAlignment:NSTextAlignmentLeft];
        _orderCodeLabel.textColor = HexColor(0x333333);
        _orderCodeLabel.font = [UIFont systemFontOfSize:14];
        
        [self.contentView addSubview:_orderCodeLabel];
    }
    return _orderCodeLabel;
}
- (UILabel *)orderStateLabel {
    
    if (!_orderStateLabel) {
        _orderStateLabel = [[UILabel alloc] init];
        [_orderStateLabel setTextAlignment:NSTextAlignmentRight];
        _orderStateLabel.textColor = ThemeMaoColor;
        _orderStateLabel.font = [UIFont systemFontOfSize:14];
        
        [self.contentView addSubview:_orderStateLabel];
    }
    return _orderStateLabel;
}
- (UILabel *)orderTimeLabel {
    
    if (!_orderTimeLabel) {
        _orderTimeLabel = [[UILabel alloc] init];
        [_orderTimeLabel setTextAlignment:NSTextAlignmentLeft];
        _orderTimeLabel.textColor = HexColor(0x999999);
        _orderTimeLabel.font = [UIFont systemFontOfSize:12];
        
        [self.contentView addSubview:_orderTimeLabel];
    }
    return _orderTimeLabel;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
